﻿using DapperExtensions;
using DapperExtensions.Mapper;
using DapperExtensions.Sql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using DapperExtensions;
using WMLogistics.Model;
using Dapper;

namespace WMLogistics_Dao
{
    public class WuliuCompanyBusiness
    {

        public int Add(wuliu_wlcompany_business apply)
        {
            using (var conn = ConnectionHelper.OpenConnection())
            {
                return conn.Insert<wuliu_wlcompany_business>(apply);
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(wuliu_wlcompany_business model)
        {
            using (var conn = ConnectionHelper.OpenConnection())
            {
                StringBuilder str = new StringBuilder();
                StringBuilder strSql = new StringBuilder();
                strSql.Append("update wuliu_wlcompany_business set ");
                if (model.wuliu_id.IfNotNull())
                    strSql.Append("wuliu_id=@wuliu_id,");
                if (model.wuliu_no.IfNotNull())
                    strSql.Append("wuliu_no=@wuliu_no,");
                if (model.wuliu_name.IfNotNull())
                    strSql.Append("wuliu_name=@wuliu_name,");
                if (model.city_id.IfNotNull())
                    strSql.Append("city_id=@city_id,");
                if (model.city_name.IfNotNull())
                    strSql.Append("city_name=@city_name,");
                if (model.state.IfNotNull())
                    strSql.Append("state=@state,");
                if (model.out_num.IfNotNull())
                    strSql.Append("out_num=@out_num,");
                if (model.sign_num.IfNotNull())
                    strSql.Append("sign_num=@sign_num,");
                if (model.breach_num.IfNotNull())
                    strSql.Append("breach_num=@breach_num,");
                if (model.contract_no.IfNotNull())
                    strSql.Append("contract_no=@contract_no,");
                if (model.bail_num.IfNotNull())
                    strSql.Append("bail_num=@bail_num");
                str.Append(strSql.ToString().TrimEnd(','));
                str.Append(" where id=@id ");
                return conn.Execute(str.ToString(), model);
            }
        }
    }
}
